<template>
  <div id="app2">
    <el-container>
      <el-aside width="200px">
        <el-row class="tac">
          <el-col :span="12" id="left">
            <el-menu
              default-active="2"
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose"
              :default-openeds="['2']"
            >
              <el-menu-item index="3">
                <span slot="title">欢迎光临:&nbsp;{{ username }}</span>
              </el-menu-item>
              <el-submenu index="2">
                <template slot="title">
                  <i class="el-icon-document"></i>
                  <span>页面管理</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item index="1-4" id="el" @click="myshop4"
                    >食品管理</el-menu-item
                  >
                  <el-menu-item
                    index="1-5"
                    id="el"
                    @click="myshop5"
                    class="span"
                    >订单管理</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-main>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item><a href="/">订单管理</a></el-breadcrumb-item>
          <el-dropdown>
            <span class="el-dropdown-link">
              个人中心<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>个人资料</el-dropdown-item>
              <el-dropdown-item>修改密码</el-dropdown-item>
              <el-dropdown-item @click="tuichu">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-breadcrumb>

        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="goods_id" label="食品名称"> </el-table-column>
          <el-table-column prop="user_id" label="顾客名称"> </el-table-column>
          <el-table-column label="骑手信息">
            <template slot-scope="scope">
              <p v-if="scope.row.rider_id">{{ scope.row.rider_id }}</p>
              <p v-else>骑手暂未接单哦</p>
            </template>
          </el-table-column>
          <el-table-column prop="odate" label="下单时间"> </el-table-column>
          <el-table-column prop="gprice" label="订单价格"></el-table-column>
          <el-table-column label="订单状态">
            <template slot-scope="scope">
              <el-button v-if="scope.row.gflag == 1" type="primary"
                >已下单</el-button
              >
              <el-button v-else-if="scope.row.gflag == 2" type="success"
                >制作中</el-button
              >
              <el-button v-else-if="scope.row.gflag == 3" type="info"
                >派送中</el-button
              >
              <el-button v-else type="warning">已完成</el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <div class="btnWrap">
                <el-button
                  v-if="scope.row.gflag != 4"
                  @click="edit(scope.row._id, scope.row.gflag)"
                  type="success"
                  >确认送达</el-button
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import dsorderModel from "../../model/dsorderModel";
import userinfo from "../../model/userinfoModel";
import * as echarts from "echarts";
export default {
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      input: "",
      username: "",
      tableData: [],
      value: [],
      qs: [],
    };
  },
  async created() {
    let info = window.localStorage.getItem("username");
    this.username = info;
    let { data: list } = await dsorderModel.query({ user_id: this.username });
    this.tableData = list.data;

    let { data: list1 } = await userinfo.getAll();
    this.qs = list1.data.filter((item) => item.type == 1);
  },
  methods: {
    async setrider(oid, qid, flag) {
      if (flag == 2) {
        this.tableData.map((item) => {
          if (item._id == oid) {
            item.rider_id = qid;
            item.gflag = 3;
          }
          return item;
        });

        await dsorderModel.update({ rider_id: qid, gflag: 3 }, oid);
        this.$message({
          type: "success",
          message: "以为" + qid + "骑手派单",
        });
      } else {
        this.value[oid] = "";
        this.$message({
          type: "error",
          message: "请先确认接单",
        });
      }
    },
    async edit(id, flag) {
      if (flag >= 3) {
        await dsorderModel.update({ gflag: 4 }, id);
        this.tableData.map((item) => {
          if (item._id == id) {
            item.gflag = 4;
          }
          return item;
        });
        this.$message({
          type: "success",
          message: "订单以完成，祝您用餐愉快",
        });
      } else {
        this.$message.error("商家和骑手都没有准备好哦，心急吃不了热豆腐");
      }
    },
    myshop4() {
      this.$router.push("/ds/customer");
    },
    myshop5() {
      this.$router.push("/ds/customer/order");
    },
    shouye() {
      this.$router.push("/ds/customer");
    },
    tuichu() {},
    handleOpen() {},
    handleClose() {},
    handleRemove(file) {
      console.log(file);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload(file) {
      console.log(file);
    },
  },
};
</script>

<style >
.el-message-box span {
  color: #000;
}
.el-message-box__btns button:nth-child(2) span {
  color: #fff;
}
.btnWrap {
  display: flex !important;
}
#el {
  color: #fff;
}

.div {
  margin-bottom: 20px;
}
.el-breadcrumb {
  border-bottom: 1px solid gray;
  margin-bottom: 20px;
}
.el-main {
  padding: 0;
  margin-left: 20px;
}
.el-aside {
  overflow: hidden;
}
#chart1,
#chart2,
#chart3,
#chart4 {
  height: 350px;
  margin: 20px 0;
}
.el-row {
  margin: 0 !important;
}
.el-aside {
  position: fixed;
}
.el-main {
  padding-left: 200px;
}
</style>
